package com.backend.mapper;

import com.backend.entity.entity.Users;
import com.backend.entity.entity.WorkOrders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 作者:xuSen
 * 日期2025/7/19 11:18
 */
@Mapper
public interface UserMapper {

    @Select("Select * from work_orders where user_id=#{userId} ")
    List<WorkOrders> GetAllOrderByUserId(Integer userId);

    @Select("select * from work_orders where user_id=#{userid} AND order_id=#{orderid}")
    WorkOrders GetOrderByUseridAndOrderid(int userid, int orderid);

    @Update("Update work_orders Set feedback=#{feedback},rating =#{rating} where user_id=#{userid} And order_id=#{orderid}")
    void UpdateComment(int userid, int orderid, String feedback, int rating);

    @Insert("Insert into work_orders(user_id,repairman_id,device_code,description,contact_info,create_time,status) VALUES (#{userid},1,#{deviceCode},#{description},#{contactinfo},#{createTime},1)")
    void commit(int userid, String description, String contactinfo, String deviceCode, LocalDateTime createTime);

    @Select("select count(*) From work_orders ")
    int getMaxid();
    @Select("select username from users where role=1 AND user_id=#{userid}")
    String GetNameByid(int userid);

}
